package mapper

import (
	"github.com/beego/beego/v2/client/orm"
	"ksd-social-api/modules/note/model"
)

type NoteCategoryMapper struct{}

/**
 * 查找小册分类
 * @author feige
 * @date 2023-11-03
 * @version 1.0
 * @desc
 */
func (mapper *NoteCategoryMapper) FindCategories(channelId uint64, systemId uint64) ([]model.NoteCategory, error) {
	// 获取数据库链接
	mysql := orm.NewOrm()
	// 准备一个切片容器
	var categorys []model.NoteCategory
	// 执行查询
	_, err := mysql.Raw("select id,title,icon,parent_id from xk_note_category where channel_id = ? and  status = 1 and is_deleted = 0 and system_id = ? order by sorted ").SetArgs(channelId, systemId).QueryRows(&categorys)
	if err != nil {
		return nil, err
	}
	return categorys, nil
}

/**
 * 查找小册分类
 * @author feige
 * @date 2023-11-03
 * @version 1.0
 * @desc
 */
func (mapper *NoteCategoryMapper) FindCategoriesAll(systemId uint64) ([]model.NoteCategory, error) {
	// 获取数据库链接
	mysql := orm.NewOrm()
	// 准备一个切片容器
	var categorys []model.NoteCategory
	// 执行查询
	_, err := mysql.Raw("select id,title,icon,parent_id,channel_id from xk_note_category where  status = 1 and is_deleted = 0 and system_id = ? order by sorted ").SetArgs(systemId).QueryRows(&categorys)
	if err != nil {
		return nil, err
	}
	return categorys, nil
}
